Repository navigation
Fix use_proxy? to correctly handle IPv6 addresses in no_proxy - #219
rodrigotomonari wants to merge 1 commit into
Conversation
| begin | ||
| return false if IPAddr.new(p_host).include?(addr) | ||
| rescue IPAddr::InvalidAddressError | ||
| next |
There was a problem hiding this comment.
The next in the rescue IPAddr::InvalidAddressError clause was removed as it is redundant. Falling off the end of the block body advances to the next iteration identically to calling next explicitly. No behavioral change.
|
@hsbt Would you mind taking a look at this? |
|
We hit this issue in Ubuntu since we now run autopkgtests with Applying this commit fixed the tests. |
The previous regex-based scan fragmented IPv6 addresses on colons, causing all IPv6 no_proxy entries to be silently ignored. Replace scan with split-then-branch parsing that handles four formats: - Bare IPv6: 2001:db8::1, 2001:db8::/32 - Bracketed: [2001:db8::1] - Bracketed with port: [2001:db8::1]:8080 - IPv4/hostname: example.com, 10.0.0.1:8080, example.com: (trailing colon) Also strips zone IDs (e.g. ::1%eth0) before IPAddr matching, and reads $2 before calling sub() to avoid global match variable clobbering. Fixes ruby#218
8814d0d to
1c4ba59
Compare
| # Bracketed IPv6: [addr] or [addr]:port | ||
| if entry =~ /\A\[([^\]]+)\](?::(\d+))?\z/ | ||
| p_port = $2 # read $2 before sub() clobbers global match variables | ||
| p_host = $1.sub(/%.*\z/, '') # strip zone ID (e.g. [::1%eth0] -> ::1) |
There was a problem hiding this comment.
Sorry for commenting on such an old PR.
Is the removal of zone IDs necessary? Since net-http and open-uri currently do not support URLs with a zone ID, it probably doesn't matter for now, but I feel it might get in the way if they support it in the future. Also, I'm concerned that sub(/%.*\z/, '') turns fe80::%eth0/64 into fe80:: (the /64 is removed as well).
I'm not very familiar with this area, so sorry if I'm missing something. I'd appreciate a review from @akr as well.
The previous regex-based scan fragmented IPv6 addresses on colons, causing all IPv6 no_proxy entries to be silently ignored.
Replace scan with split-then-branch parsing that handles four formats:
Also strips zone IDs (e.g. ::1%eth0) before IPAddr matching, and reads $2 before calling sub() to avoid global match variable clobbering.
Fixes #218